package com.xxcxcxcx.jobsystem.common.component;

import com.mojang.blaze3d.vertex.PoseStack;
import com.xxcxcxcx.jobsystem.Main;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class ProgressBarWidget extends AbstractWidget {
    //经验条组件
    private ImageWidget backGround;//经验条前景
    private ImageWidget foreGround;//经验条背景
    float percentage = 0.0f;
    int progressPix = (int)(width * percentage);

    public ProgressBarWidget(int x, int y, int width, int height, Component message) {

        super(x, y, width, height, message);
        ResourceLocation GUI_ICONS_LOCATION = new ResourceLocation(Main.MOD_ID,"textures/gui/icons.png");
        backGround = new ImageWidget(x,y,width,height,message,GUI_ICONS_LOCATION,1,64,width,5);
        foreGround = new ImageWidget(x,y,progressPix,height,message,GUI_ICONS_LOCATION,1,69,progressPix,5);
    }

    @Override
    //不知道是干啥用的
    public void updateNarration(NarrationElementOutput p_169152_) {
        this.defaultButtonNarrationText(p_169152_);
    }
    public void updatePercentage(float percentage)
    {
        this.percentage = percentage;
    }
    @Override
    public void render(PoseStack p_93657_, int p_93658_, int p_93659_, float p_93660_) {
        progressPix = (int)(width * percentage);
        foreGround.setTextureWidth(progressPix);
        foreGround.setWidth(progressPix);
        backGround.render(p_93657_,p_93658_,p_93659_,p_93660_);
        foreGround.render(p_93657_,p_93658_,p_93659_,p_93660_);
    }
}
